<template>
    <div class="app-container calendar-list-container">
      <!-- filter 条件查询 -->
      <div class="filter-container">
         <el-form :inline="true" ref="form1" :model="listQuery" :rules="rules">
            <el-form-item label="查询条件">
                  <el-select v-model="type" style="width: 100px;">
                        <el-option v-for="(item,index) in typelist" :key="index" :label="item" :value="item"></el-option>
                  </el-select>
            </el-form-item>
            <el-form-item v-if="type == '品号'" label="品号" prop="code" >
                  <el-input clearable v-model="listQuery.code" @input="circleDec" />
            </el-form-item>
            <el-form-item v-if="type == '工单'" label="单别" prop="orderType" >
                  <el-input clearable v-model="listQuery.orderType" />
            </el-form-item>
            <el-form-item v-if="type == '工单'" label="单号" prop="orderNumber" >
                  <el-input clearable v-model="listQuery.orderNumber" />
            </el-form-item>
            <el-form-item>
                  <el-button v-if="type == '品号'" class="filter-item" type="primary" v-waves icon="el-icon-search" @click="submit('form1')">查询</el-button>
                  <el-button v-if="type == '工单'" class="filter-item" type="primary" v-waves icon="el-icon-search" @click="submit('form1')">钣金组件查询</el-button>
            </el-form-item>
      </el-form>
      <el-link :underline="false" type="danger">注意：工单查询只能是钣金车间</el-link>
      </div>



      <div style="display: flex;justify-content: space-between;margin-bottom: 10px">
        <el-form :inline="true" ref="form2" :model="upform" :rules="rules2">
            <!-- @focus="findProcess" -->
            <el-form-item prop="process">
                <el-select 
                  v-model="upform.process" 
                  filterable 
                  placeholder="请选择工序"
                  class="re-item"
                  @change="changeProcess">
                  <el-option
                        v-for="(item,index) in optionsProcess"
                        :key="index"
                        :label="item.processName"
                        :value="item.processName">
                  </el-option>
                </el-select>
            </el-form-item>
            <!-- <el-form-item>
                <el-button class="filter-item" type="primary" v-waves  @click="saveprotech" v-if="deviceDarcodeLinJi">指定临技校验</el-button>
            </el-form-item> -->
            <el-form-item label="有无栈板：">
                <!-- <el-button class="filter-item" type="primary" v-waves @click="submitPallet">添加栈板</el-button>
                <el-button class="filter-item" type="primary" v-waves @click="submitPallet">取消栈板</el-button> -->
                <el-radio v-model="radio" label="1" @change="submitPallet">有栈板</el-radio>
                <el-radio v-model="radio" label="2" @change="submitPallet">无栈板</el-radio>
            </el-form-item>
            <el-button style="margin: 0 20px;" class="filter-item" type="success" v-waves icon="el-icon-circle-plus-outline" @click="addBcMpshow = !addBcMpshow">添加铭牌</el-button>
            <el-input placeholder="请输入规则" v-if="addBcMpshow" v-model="addBcMp" style="width: 200px;"></el-input>
            <el-button  v-if="addBcMpshow" type="primary" @click="mpSubmit">确定</el-button>
            <el-button style="margin: 0 20px;" class="filter-item" type="success" v-waves icon="el-icon-circle-plus-outline" @click="operationShow = !operationShow">添加运维二维码</el-button>
            <el-input placeholder="请输入规则" v-if="operationShow" v-model="operation" style="width: 200px;"></el-input>
            <el-button  v-if="operationShow" type="primary" @click="operationSubmit">确定</el-button>
        </el-form>
        <el-button
          type="button"
          class="el-button el-button--primary"
          @click="submitUpload('form2')"
          round
          size="medium"
          :loading="btnLoading"
        >
          确认提交</el-button
        >
      </div>
      <!-- <el-dialog
        title="添加包材/铭牌"
        :visible.sync="addBcMpshow"
        width="40%">
        <el-select
            v-model="addBcMp" 
            filterable 
            placeholder="请选择类型"
            style="width: 120px;margin-bottom: 20px;margin-right: 10px;"
            @change="changeProcess">
            <el-option
                  v-for="(item,index) in addBcMpList"
                  :key="index"
                  :label="item"
                  :value="item">
            </el-option>
          </el-select>
          <el-input placeholder="请输入规则" v-model="addBcMp" style="width: 300px;"></el-input>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addBcMpshow = false">取 消</el-button>
          <el-button type="primary" @click="addBcMpshow = false">确 定</el-button>
        </span>
      </el-dialog> -->
      <el-form :inline="true">
            <el-form-item prop="process" >
                  <el-button
                        @click="addCodes('code')"
                        icon="el-icon-circle-plus-outline"
                        class="el-button el-button--primary"
                        style="font-size: 15px;"
                        round>
                  </el-button>
            </el-form-item>
            
            <el-form-item prop="process" >
                <el-link type="primary" style="margin-bottom: 10px">器件表格</el-link>
            </el-form-item>
            
            <el-form-item prop="process" >
                <el-input clearable placeholder="请输入物料编码" v-model="codeOutid" @input="filterCode"/>
            </el-form-item>
      </el-form>
      <!-- table 表格 -->
      <!-- <el-link type="primary" style="margin-bottom: 10px">器件表格</el-link> -->
      <el-table
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      :data="codeList"
      :row-key="getRowKeys"
      v-loading="loading"
      element-loading-text="给我一首歌的时间"
      stripe
      border
      fit highlight-current-row style="width: 100%"
      :empty-text="emptyText"
      height="400px">
            <el-table-column :reserve-selection="true" type="selection" width="55"/>
            <el-table-column  label="序号" type="index" align="center" width="50px"/>
            <el-table-column label="元件编码"  prop="previd"  align="center" width="150px"/>
            <el-table-column label="品号"  prop="mid" align="center" width="150px"/>
            <el-table-column label="产品号"  prop="produceNo" align="center" width="150px"/>
            <el-table-column  label="规格" prop='outid' align="center" width="150px"/>
            <el-table-column  label="品名" prop='descript' align="center"/>
            <el-table-column  label="数量" prop='compositionAmount' align="center" width="120px"/>
            <!-- <el-table-column label="操作"  align="center" width="90">
                  <template slot-scope="scope" >
                        <div class="fx" style="display: flex">
                        <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="deleteData(scope.row,scope.$index,'code')"
                        ></el-button>
                        </div>
                  </template>
            </el-table-column> -->
      </el-table>

      <el-form :inline="true" style="margin: 10px 0 10px 0">
            <el-form-item prop="process" >
                  <el-button
                        @click="addCodes('attachment')"
                        icon="el-icon-circle-plus-outline"
                        class="el-button el-button--primary"
                        style="font-size: 15px;"
                        round>
                  </el-button>
            </el-form-item>
            <el-form-item prop="process" >
                <el-link type="primary">附件表格</el-link>
            </el-form-item>
            
            <el-form-item prop="process" >
                <el-input clearable placeholder="请输入物料编码" v-model="attachmentOutid" @input="filterAttachment"/>
            </el-form-item>
      </el-form>
      <!-- <el-link type="primary" style="margin: 10px 0 10px 0">附件表格</el-link> -->
      <el-table
      ref="multipleTable1"
      @selection-change="handleSelectionChange1"
      :data="attachmentList"
      :row-key="getRowKeys1"
      v-loading="loading"
      element-loading-text="给我一首歌的时间"
      stripe
      border
      fit highlight-current-row style="width: 100%"
      height="400px">
            <el-table-column  type="selection" width="55"/>
            <el-table-column  label="序号" type="index" align="center" width="50px"/>
            <el-table-column label="元件编码"  prop="previd"  align="center" width="150px"/>
            <el-table-column label="品号"  prop="mid"   align="center" width="150px"/>
            <el-table-column label="产品号"  prop="produceNo"   align="center" width="150px"/>
            <el-table-column  label="规格" prop='outid' align="center" width="240px"/>
            <el-table-column  label="品名" prop='descript' align="center"/>
            <el-table-column  label="数量" prop='compositionAmount' align="center" width="120px"/>
            <!-- <el-table-column label="操作"  align="center" width="90">
                  <template slot-scope="scope" >
                        <div class="fx" style="display: flex">
                        <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="deleteData(scope.row,scope.$index,'attachment')"
                        ></el-button>
                        </div>
                  </template>
            </el-table-column> -->
      </el-table>


      <!-- 新增器件、附件 -->
      <!-- 新增 -->
    <el-dialog
      :title="dialogTitle=='code'?'器件':'附件'"
      :visible.sync="showAddcode"
      @close="showAddcode = false;"
      width="35%"
    >
    <el-form :model="addCodeForm" ref="addCodeForm"  :rules="addRules" label-width="100px">
        <el-form-item label="元件编码:" prop="previd">
          <el-input
            clearable
            v-model="addCodeForm.previd"
          ></el-input>
        </el-form-item>
        <el-form-item label="品号:" prop="mid">
          <el-input
            clearable
            v-model="addCodeForm.mid"
          ></el-input>
        </el-form-item>
        <el-form-item label="规格:" prop="outid">
          <el-input
            clearable
            v-model="addCodeForm.outid"
          ></el-input>
        </el-form-item>
        <el-form-item label="品名:" prop="descript">
          <el-input
            type="textarea"
            autosize
            clearable
            v-model="addCodeForm.descript"
          ></el-input>
        </el-form-item>
        <el-form-item label="数量:" prop="compositionAmount">
          <el-input
            clearable
            v-model="addCodeForm.compositionAmount"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button
            type="button"
            class="el-button el-button--primary"
            @click="saveCodeForm('addCodeForm')"
          >
            保存</el-button
          >
           <el-button
            type="button"
            class="el-button el-button--warning"
            @click="showAddcode = false"
          >
            取消</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    </div>
</template>

<script>
import {savePackingMaterialsCodeCount,findsectionNo,getPtsCode,getptsCodes,getProcessList,saveProcessJobClassCodeEms,savePalletCount,delProcessJobClassCodeEms,delPalletCodeProcessEms,findLinJi,saveLinJiPro,ptsCodesList  } from '../../api/processRoute'
import { getOrderList } from '../../api/productionPlan'
export default {
    name: 'ptsCode',
    data () {
      return {
            attachmentBags:[],
            ptsCodeList:[],
            operation:'',      //运维二维码
            operationShow:false, // 运维二维码Show
            addBcMp:'',
            addBcMpshow: false,
            listQuery: {
               code: '',
            },
            tableList: {},
            codeList: [],
            attachmentList: [],
            optionsProcess: [],
            loading: false,
            rules: {
                code: [{required: true, message: '请输入品号', trigger: 'change' }],
                orderType: [{required: true, message: '请输入单别', trigger: 'change' }],
                orderNumber: [{required: true, message: '请输入单号', trigger: 'change' }],
            },
            rules2: {
                process: [{required: true, message: '请选择工序', trigger: 'change' }]
            },
            multipleSelection: [],
            multipleSelection1: [],
            upform: {},
            btnLoading: false,
            codeOutid: '',
            attachmentOutid: '',
            addCodeForm: {},
            showAddcode: false,
            // 表单校验
            addRules: {
                  previd: [
                        { required: true, message: "元件编码不能为空！", trigger: "change" },
                  ],
                  mid: [
                        { required: true, message: "品号不能为空！", trigger: "change" },
                  ],
                  outid: [
                        { required: true, message: "规格不能为空！", trigger: "change" },
                  ],
                  descript: [
                        { required: true, message: "品名不能为空！", trigger: "change" },
                  ],
                  compositionAmount: [
                        { required: true, message: "数量不能为空！", trigger: "change" },
                  ]
            },
            isrequest: false,
            dialogTitle: '',
            radio: '',
            deviceDarcodeLinJi: '',
            emptyText: '暂无数据',
            typelist:['品号', '工单'],
            type: '品号',
            produceNo: '',  // 获取的品号
            sectionNo:'',
            userInfo:{}
      }
    },
    methods: {
      // 添加运维二维码
      async operationSubmit(){
            if(!this.upform.process){
                  this.$message({
                     message: '请先选择工序',
                     type: 'warning'
                  })
                  return
            }
            if(!this.operation) return this.$message.warning('请输入运维二维码规则！')
            let selectProcess = {}
            this.optionsProcess.forEach(item => {
                  if(this.upform.process == item.processName){ selectProcess = item }
            });
            console.log(selectProcess);
            let query = {
                  technologyNo: selectProcess.technologyNo,
                  processOrder: selectProcess.processOrder,
                  type: '运维二维码',
                  code: this.operation
            }
            const res = await savePackingMaterialsCodeCount(query)
            if(res.code == '1'){
                 this.$message({
                  message:res.msg,
                  type:'success'
                  })
                  this.operationShow = false
            } else {
                  this.$message({
                  message:res.msg,
                  type:'error'
                  })
            }
      },
      // 添加铭牌
      async mpSubmit(){
            if(!this.upform.process){
                  this.$message({
                     message: '请先选择工序',
                     type: 'warning'
                  })
                  return
            }
            if(!this.addBcMp) return this.$message.warning('请输入名牌规则！')
            let selectProcess = {}
            this.optionsProcess.forEach(item => {
                  if(this.upform.process == item.processName){ selectProcess = item }
            });
            console.log(selectProcess);
            let query = {
                  technologyNo: selectProcess.technologyNo,
                  processOrder: selectProcess.processOrder,
                  type: '铭牌',
                  code: this.addBcMp
            }
            const res = await savePackingMaterialsCodeCount(query)
            if(res.code == '1'){
                 this.$message({
                  message:res.msg,
                  type:'success'
                  })
                  this.addBcMpshow = false
            } else {
                  this.$message({
                  message:res.msg,
                  type:'error'
                  })
            }
      },
      circleDec() {
	      const v1 = this.listQuery.code;
		let _this = this
		setTimeout( function() {
			const v2 = _this.listQuery.code
			if(v1 == v2){
                        if(_this.optionsProcess.length){
                              if(_this.listQuery.code != _this.optionsProcess[0].technologyNo){ _this.resetData() }
                        }
			}
		}, 300)
	},
      resetData(){
            this.codeOutid = ''
            this.attachmentOutid = ''
            this.isrequest = false
            this.tableList = []
            this.codeList = []
            this.attachmentList = []
            this.optionsProcess = []
            this.loading = false
            this.upform.process = ''
            this.radio = ''
            this.$refs.multipleTable.clearSelection();
            this.$refs.multipleTable1.clearSelection();
            this.$refs['form2'].resetFields()
      },
      submit(form){
            this.$refs[form].validate((valid) => {
                if (valid) {
                  //   this.getptsCodes()
                    this.getProcessList()
                  //   this.findLinJi()
                } else {
                    return false
                }
            })
      },
      // 获取pts条码
      async getptsCodes() {
        this.loading = true
        let query = Object.assign({},this.listQuery)
        if(this.type == '品号') {
            delete query.orderNumber
            delete query.orderType
      } else {
            delete query.orderNumber
            delete query.orderType
            query.code = this.produceNo
        }
      //   const data = this.type == '品号' ? await getptsCodes(query) : await ptsCodesList(query)
        const data = await getptsCodes(query)
        if(data.code == '1' && data.data == '') {
            this.loading = false
            this.codeOutid = ''
            this.attachmentOutid = ''
            this.isrequest = true
            this.codeList = []
            this.attachmentList= []
            this.tableList = []
            this.$message.error('请求数据为空!')
            return
        }
        let res = JSON.parse(data.data)
        if(this.type == '品号'){
            console.log('品号',res)
      } else {
            console.log('工单',res)
        }
        console.log('pts条码',res)
        if(data.code == '1' && res.code == '200'){
            
            if(res.data == '') return this.$message.error('pts条码数据为空!')
            this.tableList = res.data
            // if(this.tableList.deviceBarcodeStatus == '1'){
            //       this.emptyText = '暂无数据'
            //       this.codeList = res.data.code
            // } else if(this.tableList.deviceBarcodeStatus == '0'){
            //       this.emptyText = '发料未发完！'
            //       this.codeList = []
            // }
            this.codeList = res.data.code.length?res.data.code:[]
            this.attachmentList = res.data.attachment?res.data.attachment:[]
            if(this.userInfo.workCenter == '总装车间' && this.userInfo.lineType == 1){
                  this.attachmentList = []
                  setTimeout(async() =>{
                        let query = Object.assign({},this.listQuery)
                        delete query.code
                        const res = await ptsCodesList({},query)
                        this.ptsCodeList = JSON.parse(res.data).data
                        console.log('ptsCodeList',this.ptsCodeList)
                        this.ptsCodeList.attachmentBag.forEach(obj => {
				    // 遍历对象的所有属性  
				    Object.keys(obj).forEach(key => {
				      // 如果属性的值是数组  
				      if (Array.isArray(obj[key])) {  
				        // 遍历数组中的每个元素  
				        obj[key].forEach(item => {  
				          // 创建一个新对象，包含原始对象的id和name，以及当前数组元素的key和value  
				          // 注意：这里假设每个对象都有id和name，如果没有，需要相应调整  
				          this.attachmentList.push({  
				            ...obj, // 复制原始对象的所有属性  
				            [key]: item // 只保留当前数组元素作为新对象的属性值  
				          });  
				          // 注意：这会导致原始对象的id和name被重复，如果这不是你想要的，请调整逻辑  
				        });  
				      }  
				    });  
				  });  
                        console.log('this.attachmentList',this.attachmentList)
                        this.attachmentList.forEach(item => {
                              item.previd = this.produceNo
                              item.produceNo = this.produceNo
                              item.descript = item.attachmentBag 
                              item.outid = item.attachmentBarcode
                              item.compositionAmount = 1
                              delete item.attachmentBag
                              delete item.attachmentBarcode
                        })
                        console.log('attachmentBag',this.attachmentList)
                  },2000)
            }
            if(this.codeList.length){
                  this.codeList.forEach(item => { item.produceNo = this.listQuery.code});
            }
            if(this.attachmentList.length){
                  this.attachmentList.forEach(item => { item.produceNo = this.listQuery.code});
            }
            this.codeOutid = ''
            this.attachmentOutid = ''
            this.isrequest = true
            this.$message({
              message:  data.msg,
              type: 'success'
            })
            this.loading = false
            this.$refs.multipleTable.clearSelection();
            this.$refs.multipleTable1.clearSelection();
        } else {
            this.$message({
              message: data.msg,
              type: 'warning'
            })
        }
      },
      filterCode(){
            console.log(this.tableList.code);
            if(!this.tableList.code) return console.log('空列表')
            this.codeList = this.tableList.code.filter(data => data.outid && data.outid.includes(this.codeOutid.toString()))
      },
      filterAttachment(){
            console.log(this.tableList.attachment);
            if(!this.tableList.attachment) return console.log('空列表')
            this.attachmentList = this.tableList.attachment.filter(data => data.outid && data.outid.includes(this.attachmentOutid.toString()))
      },
      getRowKeys(row) {
            return row.outid;
      },
      getRowKeys1(row) {
            return row.outid;
      },
      handleSelectionChange(val) {
            console.log(val)
            this.multipleSelection = val;
      },
      handleSelectionChange1(val) {
            console.log(val)
            this.multipleSelection1 = val;
      },
      //选择工序
      changeProcess(val){
           this.optionsProcess.forEach(item => {
                  if(item.processName == val){
                        this.radio = !item.palletCodeCount?'2':'1'
                  }
           });
      },
      // 工单获取品号
      async getCode(){
            let query = {
                  orderType: this.listQuery.orderType,
                  workOrderNo: this.listQuery.orderNumber,
                  page: 1,
                  limit: 1000   
            }
            const res = await getOrderList(query)
            if(!res.data.records.length) return this.$message({
                message: '工单不存在',
                type: 'warning'
            })
            console.log(res.data.records[0])
            this.produceNo = res.data.records[0].produceNo
            
      },
      // 获取工序
      async getProcessList(){
            // if(!this.listQuery.code) return this.$message({
            //     message: '请先输入品号',
            //     type: 'warning'
            // })
            // if(this.optionsProcess.length) return console.log('已获取工序')
            let query
            if(this.type == '工单') {
                 let query1 = {
                  orderType: this.listQuery.orderType,
                  workOrderNo: this.listQuery.orderNumber,
                  page: 1,
                  limit: 1000  
                  }
                  const res = await getOrderList(query1)
                  if(!res.data.records.length) return this.$message({
                      message: '工单不存在',
                      type: 'warning'
                  })
                  this.produceNo = res.data.records[0].produceNo
                  this.sectionNo = res.data.records[0].sectionNo
                  const res1 = await findsectionNo({sectionNo: this.sectionNo})
                  console.log(res1)
                  this.userInfo = res1.data
                 query = {
                        technologyNo: this.produceNo,
                        technologyEnd: this.produceNo,
                        page: 1,
                        limit: 1000
                  }
            } else {
                  query = {
                        technologyNo: this.listQuery.code,
                        technologyEnd: this.listQuery.code,
                        page: 1,
                        limit: 1000
                  }
            }
            const data = await getProcessList(query)
            console.log('查询',data)
            if(data.code == '1'){
                  this.optionsProcess = data.data.records
                  this.radio = ''
                  if(this.upform.process){this.upform.process = ''}
                  this.getptsCodes()
            } else {
                  this.$message({
                     message: data.msg,
                     type: 'warning'
                  })
            }
      },
      submitUpload(form){
            if(!this.multipleSelection.length && !this.multipleSelection1.length) return this.$message({
                message: '至少选择一个',
                type: 'warning'
             })
            if(!this.upform.process){
                  this.$message({
                     message: '请先选择工序',
                     type: 'warning'
                  })
                  return
            }
            this.$refs[form].validate((valid) => {
                if (valid) {
                    this.saveProcessJobClassCodeEms()
                } else {
                    return false
                }
            })
      },
      // 提交选择的条码
      async saveProcessJobClassCodeEms(){
            let query = JSON.parse(JSON.stringify(this.multipleSelection))
            let query1 = JSON.parse(JSON.stringify(this.multipleSelection1))
            let selectProcess = {}
            this.optionsProcess.forEach(item => {
                  if(this.upform.process == item.processName){ selectProcess = item }
            });
            if(query.some(item => !item.outid)) return this.$message.error('选中的器件规格不能为空！pts系统返回')
            if(query1.some(item => !item.outid)) return this.$message.error('选中的附件规格不能为空！pts系统返回')
            query.forEach(item => {
                  item.processOrder = selectProcess.processOrder
                  item.type = '器件'
                  item.produceNo = this.type == '品号' ? this.listQuery.code : this.produceNo
                  item.outid = item.outid.trim()
                  item.previd = item.previd.trim()
                  item.compositionAmount = parseInt(item.compositionAmount)
                  console.log('query',query)
            });
            if(query1.length){
                  query1.forEach(item => {
                        let obj = {}
                        obj.produceNo = this.type == '品号' ? this.listQuery.code : this.produceNo
                        obj.processOrder = selectProcess.processOrder
                        obj.outid = item.outid?item.outid.trim():''
                        obj.compositionAmount = parseInt(item.compositionAmount)
                        obj.descript = item.descript
                        obj.mid = item.mid      
                        obj.type = '附件'
                        console.log('obj',obj)
                        query.push(obj)   
                  });
            }
            const data = await saveProcessJobClassCodeEms({ code: query})
            if(data.code == '1'){
                  this.$message({
                      message:  data.msg,
                      type: 'success'
                   })
                  this.$refs.multipleTable.clearSelection();
                  this.$refs.multipleTable1.clearSelection();
            } else if(data.code == '2') {
                  this.$message({
                      message:  data.msg,
                      type: 'error'
                   })
            }

      },
      // 是否有栈板
      async submitPallet(){
            if(!this.upform.process){
                  this.$message({
                     message: '请先选择工序',
                     type: 'warning'
                  })
                  this.radio = ''
                  return
            }
            let selectProcess = {}
            this.optionsProcess.forEach(item => {
                  if(this.upform.process == item.processName){ selectProcess = item }
            });
            let query = {
                  technologyNo: selectProcess.technologyNo,
                  processOrder: selectProcess.processOrder
            }
            if(this.radio == '1'){
                  query.type = '1'
            } else {
                  query.type = '0'
            }
            const data = await delPalletCodeProcessEms(query)
            if(data.code != '1') return this.$message.error(data.msg)
            this.$message.success(data.msg)
      },
      //删除条码
      async deleteData(row,index,type){
            if(row.isNewCode){
                  if(type == 'code') {
                        this.tableList.code.splice(index,1)
                        this.codeList.splice(index,1)
                  } else {
                        this.tableList.attachment.splice(index,1)
                        this.attachmentList.splice(index,1)
                  }
                  return
            }
            console.log(row);
            const data = await delProcessJobClassCodeEms('',{outid: row.outid})
            if(data.code == '1'){
                  if(type == 'code') {
                        this.tableList.code.splice(index,1)
                  } else {
                        this.tableList.attachment.splice(index,1)
                  }
                  this.$message({
                      message:  data.msg,
                      type: 'success'
                   })
            } else {
                  this.$message({
                     message: data.msg,
                     type: 'warning'
                  })
            }
      },
      addCodes(type){
            if(!this.isrequest) return this.$message({
                 message: '先品号查询条码!',
                 type: 'error'
            })
            this.dialogTitle = type
            this.showAddcode = true
      },
      saveCodeForm(form){
            this.$refs[form].validate((valid) => {
                  //开启校验
                  if (valid) {
                        this.addCodeForm.isNewCode = true
                        this.addCodeForm.produceNo = this.listQuery.code
                        if(this.dialogTitle == 'code'){
                              this.codeList.push(this.addCodeForm)
                              this.tableList.code = this.codeList
                              this.$refs.multipleTable.toggleRowSelection(
                                    this.codeList[this.codeList.length-1],
                                    true
                              );
                        } else {
                              this.attachmentList.push(this.addCodeForm)
                              this.tableList.attachment = this.attachmentList
                              this.$refs.multipleTable1.toggleRowSelection(
                                    this.attachmentList[this.attachmentList.length-1],
                                    true
                              );
                        }
                        
                        this.addCodeForm = {}
                        this.showAddcode = false
                  } else {
                  //校验不通过
                  
                  console.log("校验失败");
                  return false;
                  }
            })
      },
      // 工艺指定那个工序需要临技校验
      // async saveprotech(){
      //       if(!this.upform.process) return this.$message({
      //             message: '请先选择工序',
      //             type: 'warning'
      //       })
      //       let selectProcess = {}
      //       this.optionsProcess.forEach(item => {
      //             if(this.upform.process == item.processName){ selectProcess = item }
      //       });
      //       let query = {
      //             processOrder: selectProcess.processOrder,
      //             OrderType: this.listQuery.orderType,
      //             WorkOrderNo: this.listQuery.orderNumber
      //       }
      //       const data = await saveLinJiPro(query)
      //       if(data.code == '1'){
      //           this.$message({
      //               message: data.msg,
      //               type: 'success'
      //           })
      //       }
      // },
      // 查询创建的临技
      // async findLinJi() {
      //       let query = {
      //           WorkOrderNo: this.listQuery.orderNumber,
      //           OrderType: this.listQuery.orderType
      //       }
      //       const {data} = await findLinJi(query)
      //       this.deviceDarcodeLinJi = data.deviceDarcodeLinJi
      // },  
    }
}
</script>
<style>
.l-input{
  width: 400px;
  margin-top: 10px;
}
.tpc .el-time-spinner__wrapper {
  width:100% !important;
}
.tpc .el-scrollbar:nth-of-type(2) {
  display: none !important;
}
.border{
  border-color: #F56C6C !important;
}
</style>